<template>
	<el-container>
	  <el-aside width="25%"> 
	  <div class="selectRegister" >
		<el-form ref="Register"  :model="user" label-width="80px">
			<el-form-item label="姓名:">
		     <el-input v-model="user.RealName" placeholder="请输入查询的姓名"></el-input>
			  				        </el-form-item>
			  				        <el-form-item label="病历号:">
			  				            <el-input v-model="user.CaseNumber" placeholder="请输入查询的病历号"></el-input>
			  				        </el-form-item>
			  				      </el-form>
			  					  <div align="center">
			  						  <el-button @click="selectRegister()">查询</el-button>
			  					  </div>			  					  
			  				  </div>
			  				  <div style="border-bottom: 1px solid #000000;">
			  					  <p>未确诊患者信息</p>
			  				  </div>
			  				  <div style="margin: 5px;">
			  						<el-table
			  						    :data="register"
			  						    border>
			  						    <el-table-column
			  						      fixed
			  						      prop="caseNumber"
			  						      label="病历号"
			  						      width="75%">
			  						    </el-table-column>
			  						    <el-table-column
			  						      prop="realName"
			  						      label="姓名"
			  						      width="75%">
			  						    </el-table-column>
			  						    <el-table-column
			  						      prop="age"
			  						      label="年龄"
			  						      width="75%">
			  						    </el-table-column>
			  						    <el-table-column
			  						      fixed="right"
			  						      label="操作"
			  							  width="60%">
			  						      <template slot-scope="scope">
			  						        <el-button @click="handleClick(scope.row.id,scope.row.realName,scope.row.userID)" type="text" size="small" icon="el-icon-edit"></el-button>
			  						      </template>
			  						    </el-table-column>
			  						  </el-table>
			  				 </div>
		</el-aside>
	  <el-main>
		  <div class="top">
		       &nbsp;<span>{{username}}</span>&nbsp;&nbsp;
				 <span>已选择项目</span>
		   	</div>
			<!-- 已选择项目列表start -->
			 <el-table
			      :data="selectItem2"
			      style="width: 100%">
				  <el-table-column
				    label="保存"
				    width="100%">
					<template slot-scope="scope">
						<el-link type="primary" @click="temporaryStorage(scope.row.id,scope.row.registID,scope.row.itemID,scope.row.name,scope.row.objective,scope.row.isUrgent,scope.row.num)">暂存</el-link>&nbsp;
					<el-link type="primary" @click="openItem(scope.row.id,scope.row.registID,scope.row.itemID,scope.row.name,scope.row.objective,scope.row.isUrgent,scope.row.num)">开立</el-link>
					</template>	
				  </el-table-column>
			      <el-table-column
			        prop="itemID"
			        label="项目ID"
			        width="90%">
			      </el-table-column>
			      <el-table-column
			        prop="name"
			        label="项目名称"
			        width="150%">
			      </el-table-column>
			      <el-table-column
			        label="操作"
					width="190%">
					<template slot-scope="scope">
					 <el-button @click="updateItem(scope.row.id,scope.row.itemID,scope.row.name,scope.row.objective,scope.row.isUrgent,scope.row.num,scope.row.state)" size="mini" type="primary" icon="el-icon-edit" circle></el-button>
					 <el-button @click="deleteItem(scope.row.id,scope.row.name,scope.row.state)" size="mini" type="danger" icon="el-icon-delete" circle></el-button>
					 <el-button @click="cancelItem(scope.row.id,scope.row.name,scope.row.state)" size="mini" type="info">作废</el-button>
					</template>
			      </el-table-column>
				  <el-table-column
				    label="查看详细信息"
					width="100%">
					<template slot-scope="scope">
					<el-link @click="selectSingle(scope.row.id)" type="primary">查看详细信息</el-link>	
					</template>
				  </el-table-column>
			    </el-table>
				<!-- 已选择项目列表start -->
				<!-- 修改弹框start -->
				<el-dialog
				  title="修改"
				  :visible.sync="dialogVisible"
				  width="30%">
				  &nbsp;&nbsp;&nbsp;<span style="font-size: 14px;">项目ID：{{itemID}}</span>
				  <br />
				  <br />
				  &nbsp;&nbsp;&nbsp;<span style="font-size: 14px;">项目名称：{{itemName}}</span>
				  <el-form ref="queryItem" :model="queryItem" label-width="100px" style="margin-top: 20px;">
				    <el-form-item label="项目目的要求">
				      <el-input v-model="queryItem.Objective"></el-input>
				    </el-form-item>
					<el-form-item label="是否加急">
					  <el-radio v-model="queryItem.IsUrgent" label="1">是</el-radio>
					  <el-radio v-model="queryItem.IsUrgent" label="2">否</el-radio>
					</el-form-item>
					<el-form-item label="项目目的要求">
					 <el-input-number v-model="queryItem.Num" :min="1" :max="10"></el-input-number>
					</el-form-item>
				  </el-form>
				  <span slot="footer" class="dialog-footer">
				    <el-button @click="dialogVisible = false">取 消</el-button>
				    <el-button type="primary" @click="updateSubmit()">确 定</el-button>
				  </span>
				</el-dialog>
				<!-- 修改弹框end -->
				<!-- 查看详细信息start -->
				<el-dialog
				  title="提示"
				  :visible.sync="dialogVisiblechakan"
				  width="30%"
				  :before-close="handleClose">
				  <span style="font-size: 15px;">检查项目ID:{{queryItem2.id}}</span><br />
				  <span style="font-size: 15px;">检查项目名称:{{queryItem2.name}}</span><br />
				  <span style="font-size: 15px;">项目检查目的要求:{{queryItem2.objective}}</span><br />
				  <span style="font-size: 15px;">是否加急:{{queryItem2.isUrgent}}</span><br />
				  <span style="font-size: 15px;">检查结果:{{queryItem2.result}}</span><br />
				  <span style="font-size: 15px;">检查状态:{{queryItem2.state}}</span><br />  
				  <span slot="footer" class="dialog-footer">
				    <el-button @click="dialogVisiblechakan = false">取 消</el-button>
				    <el-button type="primary" @click="dialogVisiblechakan = false">确 定</el-button>
				  </span>
				</el-dialog>
				<!-- 查看详细信息end -->
	</el-main>
	   <el-aside width="25%">
		   <div class="top" style="padding-left:40%;">
		   		<el-link type="primary" @click="addItem()">新增项目</el-link> 
		   	</div>
			<div style="margin: 15px;">
			  <el-input placeholder="请输入内容" v-model="item.itemName" class="input-with-select">
			    <el-button slot="append" icon="el-icon-search" @click="selectItemMeg()" ></el-button>
			  </el-input>
			</div>
			<div>
				<el-table
				      :data="fmeditem"
				      border>
				      <el-table-column
					    fixed
				        label="选择"
				        width="50%">
						<template slot-scope="scope">
							<el-checkbox style="text-align: center;" v-model="scope.row.checked" @change="selectCheck(scope.row.id,scope.row.itemCode,scope.row.itemName,scope.row.checked)"></el-checkbox>
						</template>
				      </el-table-column>
				      <el-table-column
				        prop="itemCode"
				        label="项目编号"
				        width="100%">
				      </el-table-column>
				      <el-table-column
				        prop="itemName"
				        label="项目名称"
						 width="165%">
				      </el-table-column>
				    </el-table>
			</div>
		<el-drawer
		  title="我是标题"
		  :visible.sync="drawer"
		  direction="rtl"
		  size="60.5%"
		  :with-header="false">
		  <span>填写项目信息</span>
		  <el-table
		        :data="selectItem"
		        style="width: 100%">
		        <el-table-column
		          prop="name"
		          label="检查项目名称"
		          width="200%">
		        </el-table-column>
		        <el-table-column
		          label="项目目的要求"
		          width="355%">
				  <template slot-scope="scope">
					<el-input v-model="scope.row.objective" placeholder="请输入目的要求"></el-input>
				  </template> 
		        </el-table-column>
				<el-table-column
				  label="数量"
				  width="140%">
				  <template slot-scope="scope">
					<el-input-number size="mini" v-model="scope.row.num" :min="1" :max="10"></el-input-number>
				  </template> 
				</el-table-column>
		        <el-table-column
		          label="是否加急"
				  width="80%">
				  <template slot-scope="scope">
					<el-radio v-model="scope.row.isUrgent" label="1">是</el-radio>
				    <el-radio v-model="scope.row.isUrgent" label="2">否</el-radio>  
				  </template>
		        </el-table-column>
		      </el-table>
			  <div class="demo-drawer__footer">
		      <el-button @click="cancelForm">取 消</el-button>
		      <el-button type="primary" @click="handleClose">确认</el-button>
		      </div>
		</el-drawer>
		
	   </el-aside>
	   
	</el-container>
	
</template>

<script>
	export default {
		name:"inspectionApplication",
	    data() {
	      return {
			  dialogVisiblechakan:false,
			  itemID:"",
			  itemName:"",
			  dialogVisible:false,
			  CheckOperID:"",
			  username:"",
			  drawer:false,
			  registerID:"",
			  user:{
			  	RealName:"",
			  	CaseNumber:"",
				ID:"",
				RegistLeID:"",
				CheckOperID:"",
			  },
	          register:[],
			  fmeditem:[],
			  item:{
				itemName :"",
			  },
			  queryItem:{
				  ID:"",
				  MedicalID:"",
				  RegistID:"",
				  ItemID:"",
				  Name:"",
				  Objective:"",
				  IsUrgent:"",
				  Num:"",
				  Result:"",
				  State:0,
			  },
			  queryItem2:{
			  			id:"",
			  			medicalID:"",
			  			registID:"",
			  			itemID:"",
			  			name:"",
			  			objective:"",
			  			isUrgent:"",
			  			num:"",
			  				  result:"",
			  				  state:0,
			  },
			  selectItem:[],
			  selectItem2:[],
	      };
	    },
		mounted(){
			this.selectRegister();
			this.selectItemMeg();
		},
	    methods: {
			//查看单个信息
			selectSingle(id){
				this.dialogVisiblechakan=true;
				var item={
					ID:"",
				}
				item.ID=id;
				let url='/inspectionApplication/InquireInspectionApplication';
				let param=this.$qs.stringify(item);
				this.$axios.post(url,param)
				.then((resp)=>{
					this.queryItem2=resp.data;
					console.log(this.queryItem2);
					if(this.queryItem2.isUrgent==1){
						this.queryItem2.isUrgent="是";	
					}else{
						this.queryItem2.isUrgent="否"
					}
					if(this.queryItem2.state==1){
						this.queryItem2.state="暂存";
					}else if(this.queryItem2.state==2){
						this.queryItem2.state="已开立";
					}else if(this.queryItem2.state==3){
						this.queryItem2.state="已缴费";
					}else if(this.queryItem2.state==4){
						this.queryItem2.state="已登记";
					}else if(this.queryItem2.state==5){
						this.queryItem2.state="执行完";
					}else{
						this.queryItem2.state="已退费";
					}
				})
			},
			//废除选择的项目
			cancelItem(id,name,state){
				var item={
					ID:"",
					State:"",
				};
				item.State=state;
				item.ID=id;
				 this.$confirm('确定废除'+name+'项目吗？', '提示', {
				          confirmButtonText: '确定',
				          cancelButtonText: '取消',
				          type: 'warning'
				        }).then(() => {
						  let url='/inspectionApplication/NullifyInspectionApplication';
						  let param=this.$qs.stringify(item);
						  this.$axios.post(url,param)
						  .then((resp)=>{
						  	 this.$message(resp.data);
							 var register = {
							     ID:0,
							 }
							 register.ID=this.registerID;
							 this.selectAllitem(register);
						  })
						  .catch((err)=>{
						  	console.log('error=',err);
						  })
				        }).catch(() => {
				          this.$message({
				            type: 'info',
				            message: '已取消删除'
				          });          
				        });
			},
			//删除选择的项目
			deleteItem(id,name,state){
				var item={
					ID:"",
					State:"",
				};
				item.State=state;
				item.ID=id;
				 this.$confirm('确定删除'+name+'项目吗？', '提示', {
				          confirmButtonText: '确定',
				          cancelButtonText: '取消',
				          type: 'warning'
				        }).then(() => {
						  let url='/inspectionApplication/DeleteInspectionApplication';
						  let param=this.$qs.stringify(item);
						  this.$axios.post(url,param)
						  .then((resp)=>{
						  	 this.$message(resp.data);
							 var register = {
							     ID:"",
							 }
							 register.ID=this.registerID;
							 this.selectAllitem(register);
						  })
						  .catch((err)=>{
						  	console.log('error=',err);
						  })
				        }).catch(() => {
				          this.$message({
				            type: 'info',
				            message: '已取消删除'
				          });          
				        });
			},
			//提交修改
			updateSubmit(){
				console.log(this.queryItem);
				this.dialogVisible=false;
				let url='/inspectionApplication/UpdateInspectionApplication';
				let param=this.$qs.stringify(this.queryItem);
				this.$axios.post(url,param)
				.then((resp)=>{
					 this.$message(resp.data);
				})
				.catch((err)=>{
					console.log('error=',err);
				})
			},
			//修改选择的项目
			updateItem(id,itemid,name,objective,isUrgent,num,state){
				this.dialogVisible=true;
				this.itemID=itemid;
				this.itemName=name;
				this.queryItem.ID=id;
				this.queryItem.Objective=objective;
				this.queryItem.IsUrgent=isUrgent;
				this.queryItem.Num=num;
				this.queryItem.State=state;
				this.queryItem.Name=name;
				this.queryItem.ItemID=itemid;
				this.queryItem.RegistID=this.registerID;
			},
			//提交已选择的项目
			openItem(ID,RegistID,id,Name,Objective,IsUrgent,num){
				var item={
					ID:"",
					RegistID:"",
					ItemID:"",
					Name:"",
					Objective:"",
					IsUrgent:"",
					Num:0,
					DoctorID:"",
					State:"",
				}
				item.ID = ID;
				item.RegistID = this.registerID;
				item.ItemID = id;
				item.Name = Name;
				item.Objective = Objective;
				item.IsUrgent = IsUrgent;
				item.Num = num;
				item.DoctorID = this.CheckOperID;
				item.State = 2;
				console.log("item.Num"+item.Num);
				console.log("item="+item);
				let url='/inspectionApplication/TemporaryItems';
				let param=this.$qs.stringify(item);
				this.$axios.post(url,param)
				.then((resp)=>{
					 this.$message(resp.data);
				})
				.catch((err)=>{
					console.log('error=',err);
				})
			},
			//暂存已选择项目
			temporaryStorage(ID,RegistID,id,Name,Objective,IsUrgent,num){
				var item={
					ID:"",
					RegistID:"",
					ItemID:"",
					Name:"",
					Objective:"",
					IsUrgent:"",
					Num:0,
					DoctorID:"",
					State:"",
				}
				item.ID = ID;
				item.RegistID = this.registerID;
				item.ItemID = id;
				item.Name = Name;
				item.Objective = Objective;
				item.IsUrgent = IsUrgent;
				item.Num = num;
				item.DoctorID = this.CheckOperID;
				item.State = 1;
				console.log("item.Num"+item.Num);
				console.log("item="+item);
				let url='/inspectionApplication/TemporaryItems';
				let param=this.$qs.stringify(item);
				this.$axios.post(url,param)
				.then((resp)=>{
					 this.$message(resp.data);
				})
				.catch((err)=>{
					console.log('error=',err);
				})
			},
			//选择抽屉的确定
			handleClose() {
				for(var i=0;i<this.selectItem.length;i++){
					this.selectItem2.push(this.selectItem[i]);
				}
				this.selectItem=[];
				console.log(this.selectItem2);
			     this.drawer = false; 
			    },
				//选择抽屉的取消
			    cancelForm() {
				  this.selectItem=[];
			      this.drawer = false;
			    },
			//查询患者未确诊信息
	      selectRegister(){
	      	// let url='/UserController';
	      	let url='/inspectionApplication/selectNoDiagnosisRegister';
	      	let param=this.$qs.stringify(this.user);
	      	this.$axios.post(url,param)
	      	.then((resp)=>{
	      		this.register =resp.data;
	      	})
	      	.catch((err)=>{
	      		console.log('error=',err);
	      	})
	      },
		  //查询项目名称
		  selectItemMeg(){
			let url='/inspectionApplication/inquireInspection';
			let param=this.$qs.stringify(this.item);
			this.$axios.post(url,param)
			.then((resp)=>{
				this.fmeditem =resp.data;
			})
			.catch((err)=>{
				console.log('error=',err);
			})
		  },
		  //点击多选框
		  selectCheck(id,itemid,itemName,checked){
			  console.log(checked);
			  var queryItem = {
				ID:"",
				itemID:"", 
				name:"",
				registID:"",
				isUrgent:"",
			  };
			  queryItem.ID=id;
			  queryItem.itemID=id;
			  queryItem.name=itemName;
			  queryItem.registID=this.registerID;
			  queryItem.isUrgent="2";
			  if(checked==true){
				this.selectItem.push(queryItem);  
			  }
			  
		  },
		  //点击新增按钮
		  addItem(){
			  if(this.registerID!=''){
				this.drawer = true;  
			  }else{
				 this.$message("请先选择患者");
			  }
			  console.log(this.fmeditem[0]);
		  },
		  //点击患者操作那儿儿
		  handleClick(id,realname,checkOperID){
			this.registerID=id;
			this.username=realname;
			this.CheckOperID=checkOperID;
			var register = {
			    ID:"",
			}
			register.ID=id;
			console.log(register.id);
			this.selectAllitem(register);
		    },
			//查询已选择的所有项目
			selectAllitem(register){
			let url='/inspectionApplication/InquireCheckApply';
			let param=this.$qs.stringify(register);
			this.$axios.post(url,param)
			.then((resp)=>{
				this.selectItem2 =resp.data;
			})
			.catch((err)=>{
				console.log('error=',err);
			})
			}
			//新增
	    },
	  }
</script>

<style>
	html, body, #app, .el-container .el-main{
	    /*统一设置高度为100%*/
	    height: 100%;
		padding: 0px;
	}
	.el-aside {
		height: 100%;
	  }
	  .el-main {
		height: 100%;
		border-right: #000000 1px solid;
		border-top: #000000 1px solid;
		border-left: #000000 1px solid;
		}
	 .selectRegister{
	 	padding: 10px 15px;
	 	border-bottom: 1px solid black;
	 }
	 .top{
	 		background-color: #D7D7D7;
	 		height: 30px;
	 		line-height: 25px;
	 } 
	 .demo-drawer__footer{
		margin-top: 10px;
		margin-left: 40%;
	 }
</style>
